#!/usr/bin/python3
# -*- coding: utf-8 -*-
# @Time : 2021/9/10 10:10
# @Author : lenovo
# @Email : 26541796406@qq.com
# @File : CRM_ST_BG_505.py
# @Project : crm
"""查看公告信息"""
from selenium import webdriver
from time import sleep
from selenium.webdriver.common.by import By
"""选择Chrome浏览器，将driverAlert化，打开crm网页"""
driver = webdriver.Chrome()
driver.get('http://192.168.1.139/crm3')
sleep(2)
"""找到用户名，密码输入框以及登录按钮"""
username_locator = driver.find_element_by_name('name')
password_locator = driver.find_element_by_name('password')
login_locator = driver.find_element_by_xpath("/html/body/div[2]/div/div[2]/div/form/fieldset/input[3]")
"""输入用户名，密码，点击登录"""
username_locator.send_keys('admin')
password_locator.send_keys('123456')
login_locator.click()
sleep(3)
"""
 这是在获取cookies值
 以后就可以免登录，直接绕过登录页面
cookies = driver.get_cookies()
cookie = {}
for k,v in cookies[0].items():
    if k == 'name' or k == 'value':
        cookie[k] = v
print(cookie)
"""
cookie = {'name': 'PHPSESSID', 'value': 'i1mj8tbl7cp4pt11rijh3toul0'}
driver.get('http://192.168.1.139')
sleep(1)
driver.maximize_window()
driver.add_cookie(cookie)
"""直接获得公告首页页面网址"""
driver.get('http://192.168.1.139/crm3/index.php?m=announcement')
sleep(2)
"""进行查看的操作"""
# 创建定位器
notice_amending_locator = (By.LINK_TEXT,'查看')  # 公告查看按钮
notice_anthor_locator = (By.LINK_TEXT,'admin')  # 作者信息

# 具体操作
driver.find_elements(*notice_amending_locator)[0].click()
sleep(2)
driver.close()